package patterns.composite;

/**
 * Created by lenovo on 2016/11/25 0025.
 * 组合模式演示
 */
public class CompositePatternDemo {
    public static void main(String[] args) {
        //顶级CEO
        Employee CEO = new Employee("John", "CEO", 30000);
        //次级管理者
        Employee CTO = new Employee("Jack", "CTO", 20000);
        Employee CFO = new Employee("Mary", "CFO", 20000);
        //技术部员工
        Employee engineer1 = new Employee("Tom", "engineer", 10000);
        Employee engineer2 = new Employee("Jee", "engineer", 10000);
        //财务部员工
        Employee accountant1 = new Employee("Candi", "accountant", 10000);
        Employee accountant2 = new Employee("Any", "accountant", 10000);
        //将下级部门员工，添加组合到上层对象中，属于其所辖。
        CEO.add(CFO);
        CEO.add(CTO);

        CTO.add(engineer1);
        CTO.add(engineer2);

        CFO.add(accountant1);
        CFO.add(accountant2);

        //输出显示各层级员工信息
        System.out.println(CEO);//顶级ceo
        for (Employee headEmployee : CEO.getSubordinates()) {
            //两个次级管理者
            System.out.println(headEmployee);
            //对应各自管辖的普通员工
            for (Employee e : headEmployee.getSubordinates()) {
                System.out.println(e);
            }
        }
    }
}
